#include <bits/stdc++.h>
using namespace std;

int n,m,mxn,xmsum=0,ymsum=0,ans=0;
int arr[105][105];
int lenmax(int len){
    mxn=INT_MIN;
    for (int j = 1; j <= m; ++j)
            mxn=max(mxn,arr[len][j]);
    return mxn;
}

int liemin(int lie){
    mxn=INT_MAX;
    for (int i = 1; i <= n; ++i)
        mxn=min(mxn,arr[i][lie]);
    return mxn;
}

int main(){
    cin>>n>>m;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            cin>>arr[i][j];
    for (int i = 1; i <= n; ++i)
        xmsum+=lenmax(i);
    for (int j = 1; j <= m; ++j)
        ymsum+=liemin(j);
    ans=abs(xmsum-ymsum);
    cout<<ans<<endl;
    return 0;
}